package com.xzzz.irda.auth.server;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * 服务端配置
 *
 * @author wangyf
 * 
 */
@Slf4j
@Configuration
public class AuthServerConfigurationImporter {

    private BeanFactory beanFactory;

    private static AutowiredAuthServiceConfigurersIgnoreParents autowiredArthurServiceConfigurersIgnoreParents;

    @Autowired
    private void setAutowiredArthurServiceConfigurersIgnoreParents (
            AutowiredAuthServiceConfigurersIgnoreParents autowiredAuthServiceConfigurersIgnoreParents,
            AuthServerConfiguration authServerConfiguration){

        // 获取 AuthServerConfigurer, 即获取用户自定义配置类, 并执行相关配置方法, 来进行二次配置
        List<AuthServerConfigurer> list = autowiredAuthServiceConfigurersIgnoreParents.getArthurServiceConfigurers();
        list.forEach(config -> config.configure(authServerConfiguration));
    }

    @Bean
    public static AutowiredAuthServiceConfigurersIgnoreParents autowiredArthurServiceConfigurersIgnoreParents (
            ConfigurableListableBeanFactory beanFactory) {
        autowiredArthurServiceConfigurersIgnoreParents = new AutowiredAuthServiceConfigurersIgnoreParents(beanFactory);
        return autowiredArthurServiceConfigurersIgnoreParents;
    }

}
